<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>盘点订单相关的盘点订单记录</title>
    <script type="text/javascript">
      var hxId;
      Ext.onReady(function(){
        var hxesForInventoryDS = new Ext.data.Store({
          baseParams:{id:<%=params[:id]%>},
          proxy: new Ext.data.HttpProxy({
            url: '/inventory/getHxesById'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'department_name',
              mapping:'department.name'
            },{
              name: 'employee_name',
              mapping:'employee.name'
            },{
              name: 'amount'
            }, {
              name: 'description'
            }, {
              name: 'created_at'
            }, {
              name: 'updated_at'
            }])
        });
        //生成出库Grid的CM
        var hxesForInventorySM = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
        var hxesForInventoryCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),hxesForInventorySM,{
            id: 'common',
            header: 'DB',
            dataIndex: 'id',
            width: 50
          },{
            header: '部门',
            dataIndex: 'department_name',
            width: 70
          },{
            header: '编辑者',
            dataIndex: 'employee_name',
            width: 70
          },{
            header: '总金额',
            dataIndex: 'amount',
            align: 'right',
            renderer: Ext.util.Format.numberRenderer('0,000.00'),
            width: 75
          },{
            header: '描述',
            dataIndex: 'description',
            width: 230
          },{
            header: '变更日期',
            dataIndex: 'created_at',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 110
          },{
            header: '修改日期',
            dataIndex: 'updated_at',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 110
          }
        ]);
        //生成要订单的产品的Grid
        var hxesForInventoryGrid = new Ext.grid.GridPanel({
          title:'盘点订单列表',
          store: hxesForInventoryDS,
          cm: hxesForInventoryCM,
          sm: hxesForInventorySM,
          loadMask: true,
          width: 945,
          height: 230,
          frame: true
        });
        hxesForInventoryDS.load();
        
        hxesForInventoryGrid.on('rowdblclick', function(gridPanel, rowIndex, e){
          hxId = hxesForInventoryDS.getAt(rowIndex).get('id');
          var inventoryNumber = hxesForInventoryDS.getAt(rowIndex).get('order_number');
          //hxesForInventoryDS.reload();
          inventoryHxDetailDS.removeAll();
          inventoryHxDetailDS.baseParams.id = hxId;
          inventoryHxDetailDS.load();
          inventoryHxDetailGrid.setTitle("盘点订单的历史详细信息");
        });

        //--------------------------盘点订单详细，双击后可显示数据----------------
        var inventoryHxDetailDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/inventory/getHxDetailsByHxId'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'product_name',
              mapping:'product.name'
            },{
              name: 'product_number',
              mapping:'product.number'
            },{
              name: 'product_spec',
              mapping:'product.spec'
            },{
              name: 'quantity'
            }, {
              name: 'unit_price'
            }, {
              name: 'amount'
            }, {
              name: 'is_suit',
              mapping:'product.is_suit',
              convert:function(value,record){
                if(value == "1"){
                  return "套装";
                }else if(value == "0"){
                  return "单品";
                }
              }
            }, {
              name: 'description'
            }])
        });

        //生成盘点订单详细表的Grid的CM
        var inventoryHxDetailSM = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
        var inventoryHxDetailCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),inventoryHxDetailSM,{
            id: 'common',
            header: 'DB',
            dataIndex: 'id',
            width: 50
          },{
            header: '产品名称',
            dataIndex: 'product_name',
            width: 210
          },{
            header: '编号',
            dataIndex: 'product_number',
            width: 70
          },{
            header: '规格',
            dataIndex: 'product_spec',
            width: 80
          },{
            header: '数量',
            dataIndex: 'quantity',
            align: 'right',
            width: 80
          },{
            header: '单价',
            dataIndex: 'unit_price',
            align: 'right',
            renderer: Ext.util.Format.numberRenderer('0,000.00'),
            width: 70
          },{
            header: '总价',
            dataIndex: 'amount',
            align: 'right',
            renderer: Ext.util.Format.numberRenderer('0,000.00'),
            width: 70
          },{
            header: '套装或单品',
            dataIndex: 'is_suit',
            width: 70
          },{
            header: '备注',
            dataIndex: 'description',
            width: 150
          }
        ]);
        //生成要订单的产品的Grid
        var inventoryHxDetailGrid = new Ext.grid.GridPanel({
          title:'盘点订单详细列表',
          store: inventoryHxDetailDS,
          cm: inventoryHxDetailCM,
          sm: inventoryHxDetailSM,
          loadMask: true,
          width: 945,
          height: 285,
          frame: true
        });
        //总的panel
        var workbenchPanel = new Ext.Panel({
          width: 955,
          height: 640,
          frame:false,
          layout:'table',
          layoutConfig: {columns:1},
          defaults:{margins:'5 5 5 5'},
          items:[hxesForInventoryGrid,inventoryHxDetailGrid]
        });
        workbenchPanel.render("hx_for_inventory_workbench_panel");
      })
    </script>
  </head>
  <body>
    <div id="hx_for_inventory_workbench_panel"></div>
  </body>
</html>